package com.koron.css2.contractmanage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.contractmanage.ecBean.EcContractConfigBean;
import com.koron.css2.contractmanage.mapper.ContractConfigMapper;
import com.koron.css2.contractmanage.querybean.ContractManageQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class ContractConfigList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            ContractManageQueryBean queryBean = JsonUtils.objectToPojoIgnoreNone(req.getData(), ContractManageQueryBean.class);
            if (StringUtils.isBlank(queryBean.getContractType())){
                throw new RuntimeException("缺少参数");
            }
            ContractConfigMapper mapper = factory.getMapper(ContractConfigMapper.class);
            List<EcContractConfigBean> list=mapper.selectConfigByType(queryBean.getContractType());

            MessageBean<List> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询报装合同成功", List.class);
            messageBean.setData(list);
            return messageBean;
        } catch (Exception e) {
            logger.error("查询报装合同配置失败: " + e.getMessage(), e);

            return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询报装合同失败: " + e.getMessage(), null);
        }



    }
}
